<?php
namespace jy_qiuyuyue;
defined('BY_JYA') or exit('error');
/*
	消息提醒
*/
class notice extends \plugin{
	public function gettpl_data($orderid,$type=0){//type=0表单订单，type=1
		return $datas;
	}
	public function notice_yuyueorder($order,$url=''){
		//预约成功消息		
		$template_id=cfc('account')->get_tpl_template_id('OPENTM405653850','预约成功消息');
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2],'yuyueorder','预约成功消息','jy_qiuyuyue');
		}
		$serve=pdo_get('jy_qiuyuyue_serve',array('id'=>$order['serve_id'],'uniacid'=>$_SESSION['uniacid']));
		$serve_title=$serve['title'];
		$weekid=date("w",strtotime($order['day']));
		$weekid=$weekid?:7;
		$serve_time=json_decode($serve['serve_time'],true);
		$timeids=str_array($order['timeid']);
		$serve_times=array();
		foreach($timeids as $tv){
				if(intval($tv)){
					$timekey=$tv;
				}else{
					$timekey=substr($tv, 0, -1);
				}
				$fee=$serve_time[intval($timekey)]['fee']?:$serve['price'];
				if($weekid==6 && $serve['week6_addfee']>0){
					$fee +=$serve['week6_addfee'];
				}
				if($weekid==7 && $serve['week7_addfee']>0){
					$fee +=$serve['week7_addfee'];
				}
				if($item['is_ban']){
					$fee=50*$fee/100;
				}
				$serve_times[]=array(
					'times'=>$serve_time[intval($timekey)]['times'],
					'fee'=>$fee,
					'id'=>$tv,
				);
		}
		$item['serve_times']=$serve_times;
		$serve_timetitle=$order['day'].':'.$serve_times[0]['times']['start'].'~'.$serve_times[0]['times']['end'];
		$message=array(
			'first'=>array('value'=>'预约场地成功！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$serve_title,"color" => "#4a5077"),
			'keyword2'=>array('value'=>$serve_timetitle,"color" => "#4a5077"),
			'remark'=>array('value'=>'谢谢惠顾！请留意预约进度信息！点击“详情”查看预约信息。',"color" => "#4a5077"),
		);
		if(!$url){
			$url=custom_url('jy_qiuyuyue/server_order/list/status=1&id='.$order['id'],true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'yuyueorder','jy_qiuyuyue',$order['id']);
		}
	}
}
